package com.study.d3_method_reference;
//自定义比较规则1：让对象所在的类实现比较规则Comparable，重写compareTo方法，来指定比较规则
public class Student implements Comparable<Student>{
    private String name;
    private int age;
    private  char gender;
    private double height;

    public Student() {
    }

    public static int compareByAge(Student o1,Student o2){
        return o2.age - o1.age;
    }
    public Student(String name, double height, char gender, int age) {
        this.name = name;
        this.height = height;
        this.gender = gender;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                ", height=" + height +
                '}'+"\n";
    }

    @Override
    public int compareTo(Student o) {
        //
//        if(this.age>o.age){
//            return 1;
//        }else if(this.age<o.age){
//            return -1;
//        }
//        return 0;
        return this.age - o.age;  //升序
//        return o.age - this.age 降序
    }
}
